﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Enter.Entity;
using Enter.Common;
using Enter.BizLogic;
using Enter.Config;
using Enter.Web.SystemAdmin;
namespace WebSystemAdmin.GoodClass
{
    public partial class GoodClassPropertyEdit : PageBase
    {

        public int PID = RequestStrHelper.GetIntFromRequest("PID", 0);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ListCtrlHelper.BindEnumOnListControl(ddl_Status, typeof(EnumStatus));
                ListCtrlHelper.BindEnumOnListControl(ddl_PorpertyType, typeof(T106_GoodClassPropertyEntity.EnumPorpertyType));
                ListCtrlHelper.BindEnumOnListControl(ddl_chooseType, typeof(T106_GoodClassPropertyEntity.EnumchooseType));
                if (PID != 0)
                {
                    GetInfo();
                }
            }
        }

        private void GetInfo()
        {
            T106_GoodClassPropertyBLLSub bll = new T106_GoodClassPropertyBLLSub();
            T106_GoodClassPropertyEntity model = bll.GetObjectByPID(int.Parse(Request.QueryString["PID"]));
            if (model == null) return;
            txt_PID.Text = model.PID.ToString();
            txt_PNo.Text = model.PNo.ToString();
            txt_PName.Text = model.PName.ToString();
            txt_ClassID.Text = model.ClassID.ToString();
            txt_icon.Text = model.icon.ToString();
            txt_Weight.Text = model.Weight.ToString();
            txt_HitCount.Text = model.HitCount.ToString();
            txt_RootClassID.Text = model.RootClassID.ToString();
            txt_Descr.Text = model.Descr.ToString();
            txt_ISMian.Text = model.ISMian.ToString();
            this.ddl_Status.Items.FindByValue(((byte)model.Status).ToString()).Selected = true;
            this.ddl_PorpertyType.Items.FindByValue(((byte)model.PorpertyType).ToString()).Selected = true;
            txt_IsRequired.Text = model.IsRequired.ToString();
            this.ddl_chooseType.Items.FindByValue(((byte)model.chooseType).ToString()).Selected = true;
        }

        protected void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                T106_GoodClassPropertyEntity model = new T106_GoodClassPropertyEntity();
                T106_GoodClassPropertyBLLSub bll = new T106_GoodClassPropertyBLLSub();
                if (Request.QueryString["ID"] != null)
                {
                    model.PID = PID;
                }
                model.PNo = txt_PNo.Text;
                model.PName = txt_PName.Text;
                model.ClassID = txt_ClassID.Text;
                model.icon = txt_icon.Text;
                model.Weight = int.Parse(txt_Weight.Text);
                model.HitCount = int.Parse(txt_HitCount.Text);
                model.RootClassID = txt_RootClassID.Text;
                model.Descr = txt_Descr.Text;
                model.ISMian = bool.Parse(txt_ISMian.Text);
                model.Status = (EnumStatus)byte.Parse(ddl_Status.SelectedValue);
                model.PorpertyType = (T106_GoodClassPropertyEntity.EnumPorpertyType)byte.Parse(ddl_PorpertyType.SelectedValue);
                model.IsRequired = bool.Parse(txt_IsRequired.Text);
                model.chooseType = (T106_GoodClassPropertyEntity.EnumchooseType)byte.Parse(ddl_chooseType.SelectedValue);
                if (bll.Save(model)>0)
                {
                    Utils.throwErrorGotoURL("操作成功", "GoodClassPropertyList.aspx");
                }
                else
                {
                    Utils.ShowMessage("操作失败");
                }
            }
            catch (Exception ex)
            {
                Utils.ShowMessage("添加失败:" + ex.Message);
            }
        }
    }
}
